<%extends"admin/base.html"%><%block content%>
<div class="layui-card">
  <div class="layui-card-body">
    <div style="padding-bottom: 10px;">
      <button class="layui-btn layuiadmin-btn-list layui-btn-normal" data-type="add">添加</button>
    </div>
    <table id="LAY-app-friendHref-list" lay-filter="LAY-app-friendHref-list"></table>
    <script type="text/html" id="titleTpl">
        {{#
  var get_favicon = function(url) {
        var host = "null";
        if(typeof url == "undefined"
                        || null == url)
                url = window.location.href;
        var regex = /.*\:\/\/([^\/]*).*/;
        var match = url.match(regex);
        if(typeof match != "undefined"
                        && null != match)
                host = match[1];
        return "https://"+host+'/favicon.ico';
  };
}}
      <span></span><img src="{{ get_favicon(d.href) }}" alt="{{ d.title }}" class="ico"/></span>
      <span><a href="{{ d.href }}">{{ d.title }}</a></span>
    </script>
      <script type="text/html" id="hrefTpl">
      <a href="{{ d.href }}">{{ d.href }}</a>
    </script>
    <script type="text/html" id="tableTpl">
      <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
    </script>
  </div>
</div>
<%endblock%>
<%block script%>
    var active = {
      batchdel: function(){
        var checkStatus = table.checkStatus('LAY-app-friendHref-list')
        ,checkData = checkStatus.data; //得到选中的数据

        if(checkData.length === 0){
          return layer.msg('请选择数据');
        }
        layer.confirm('确定删除吗？', function(index) {
            $.each(checkData,function(index,item){
                 //执行 Ajax 后重载
                  $.ajax({
                    url: "<< url_for('admin.FriendHrefDel') >>",
                    data:{Id:item.Id},
                        dataType:'json',
                    success: function (returnData) {
                        if (returnData.status == 1) {
                            layer.msg('已删除，'+item.title);
                        }
                        else {
                            layer.msg(item.title+'，'+returnData.info);
                        }
                     }
                  });
            });
            table.reload('LAY-app-friendHref-list');
        });
      },
      add: function(){
        layer.open({
          type: 2
          ,title: '添加友链'
          ,content: "<< url_for('admin.FriendHrefAdd') >>"
          ,maxmin: true
          ,area: ['300px', '300px']
          ,btn: ['确定', '取消']
          ,yes: function(index, layero){
            //点击确认触发 iframe 内容中的按钮提交
            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
            submit.click();
          }
        });
      }
    };

    $('.layui-btn.layuiadmin-btn-list').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
    table.render({
        elem: "#LAY-app-friendHref-list",
        url: "<< url_for('admin.FriendHrefList') >>",
        text: {
            none: '暂无相关数据', //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            error:'对不起，加载出现异常！'
        },
        method:'post',
       cols: [[{field: "Id", title: "友链ID", sort: !0},
            {field: "title",title: "友链名称",minWidth: 50, templet: "#titleTpl"},
            {field: "href",title: "链接",templet:'#hrefTpl'},
            {field: "createTime",title: "创建时间"},
            {field: "upgradeTime",title: "更新时间"},
            {title: "操作",minWidth: 120,align: "center",fixed: "right",toolbar: "#tableTpl"}]],
        page: !0,
        limit: 15,
        limits: [10, 15, 20, 25, 30]
    }), table.on("tool(LAY-app-friendHref-list)", function (t) {
        var e = t.data;
        "del" === t.event ? layer.confirm("确定删除此文章？", function (er) {
            layer.close(er)
            $.ajax({
                url: "<< url_for('admin.FriendHrefDel') >>",
                data:{Id:e.Id},
                 dataType:'json',
                success: function (returnData) {
                    if (returnData.status == 1) {
                        table.reload('LAY-app-friendHref-list');
                        layer.msg('已删除，'+e.title);
                        t.del()
                    }
                    else {
                        layer.msg(e.title+'，'+returnData.info);
                    }
                 }
              });
        }) : "edit" === t.event && layer.open({
            type: 2,
            title: "编辑友链",
            content: "/admin/friend/href/edit/" + e.Id,
            maxmin: !0,
            area: ['300px', '300px'],
            btn: ["确定", "取消"],
            yes: function (e, i) {
                 var l = window["layui-layer-iframe" + e],
                a = i.find("iframe").contents().find("#layuiadmin-app-form-edit");
                a.click();
            }
        })
    })
    $('.layui-nav-child dd').removeClass('layui-this');
    $('#view_admin_friend_href').addClass('layui-this');
    $('.layui-nav-tree li').removeClass('layui-nav-itemed');
    $('#admin_system_nav').addClass('layui-nav-itemed');
<%endblock%>